var _packageType;
var drophtml;
var backhtml;
function loadDesigns(_pckgName, _showInLeftMenu)
{
    $.ajax({
			
        type: "POST",
        //url:"showbgimg.php",
        url:"getbackgroundsimages.php",
        data:{
            src:_pckgName
        } ,		
        success:function(stepTwo)
        {
            var _divId = "bannerInner";
            //alert(_showInLeftMenu);
            if(_showInLeftMenu)
            {
                if($('#addressDiv')) $('#addressDiv').hide();
                $('.dd_BG_top').html("<div style='padding-top:10px'>Choose design</div>");
                //$('.dd_BG_top').css(style='overflow: auto;')
                
                
                $('.dd_BG').html("<div id=bgz >"+stepTwo+"</div>");
                _divId = "dd_BG";
                drophtml=$('.drop').html();
                window.console.log(drophtml);
                backhtml=$('.back').html();
                window.console.log(backhtml);
            
            //alert(_divId);
            }
            else
            {
                $('#bannerInner').append("<center><div class='chooseDesign'>"+stepTwo+"</div></center>");
            }
			
            $("#" + _divId +" img").click(function(e){				
                //here
                
                var temp=($(this).prop("src"));
                var str = temp,
                delimiter = '/',
                start = 4,
                tokens = str.split(delimiter).slice(start),
                result = tokens.join(delimiter);
                //alert(result);
                CH.VC.dropbackground=result;
                
                
                $('#' + _divId).html(bannertemphtml);
                $('.maindiv').hide();
                $( ".tools button" ).prop("disabled","");
                $( ".tools input" ).prop("disabled","");
                $( ".tools select" ).prop("disabled","");
                //$(".drop").html("");
                //$('#frontdivimg').hide();
                var bg=$(this).prop("src");
                CH.VC3.result = bg.lastIndexOf(".");
                //alert(result);
                CH.VC3.result=bg.charAt(CH.VC3.result-1);
                //alert (bg);
                $.ajax({
				
                    type: "POST",
                    url:"CopyImgFrm.php",
                    data:{
                        bgsrc:bg, 
                        packageType: _packageType
                    },
                    success:function(data)
                    {
                        
                        $('.drop').css("margin-left", "0px");
                        $('.back').css("margin-left", "0px");
                        $('.drop').css("width", "580px");
                        $('.back').css("width", "580px");
                        $('.drop').css("height", "350px");
                        $('.back').css("height", "350px");
                        //alert(data); //2 possible outputss
                        var field = data.split(' ')[1];
                        
                        CH.VC.paddding = 580-field;
                        CH.VC.paddding = CH.VC.paddding/2;
                        var heightOrwidth=data[0];
                        if(heightOrwidth=="w")
                        {
                            $('.drop').css("background-width", "100%");
                            $('.back').css("background-width", "100%");
                            $('.drop').css("height", field+"px");
                            $('.back').css("height", field+"px");
                            $('.drop').css("background-repeat","no-repeat");
                            $('.back').css("background-repeat","no-repeat");
                        // alert("done");
                        }
                        else if(heightOrwidth=="h")
                        {
                            $('.drop').css("background-height", "100%");
                            $('.back').css("background-height", "100%");
                            $('.drop').css("width", field+"px");
                            $('.back').css("width", field+"px");
                            $('.drop').css("margin-left", CH.VC.paddding+"px");
                            $('.back').css("margin-left", CH.VC.paddding+"px");
                            $('.drop').css("background-repeat","no-repeat");
                            $('.back').css("background-repeat","no-repeat");
                        //   alert("done");
                        }
                        else{
                            
                            var check = data.split(' ')[0];
                            var width = data.split(' ')[1];
                            var height = data.split(' ')[2];
                            var pad=580-width;
                            pad=pad/2;
                            
                            //alert(check+" "+width+" "+height);
                            if(check=="-h")
                            {   
                               // alert("this is case in which width is greater than or equal to height but still lesser than total width");
                                $('.drop').css("width", width+"px");
                                $('.back').css("width", width+"px");
                                $('.drop').css("height", height+"px");
                                $('.back').css("height", height+"px");
                                $('.drop').css("background-repeat","no-repeat");
                                $('.back').css("background-repeat","no-repeat");
                                $('.drop').css("margin-left", pad+"px");
                                $('.back').css("margin-left", pad+"px");
                            
                            }
                            else if(check=="-w")
                            {
                               // alert("this is case in which height is greater than width but still lesser than total height");
                                $('.drop').css("width", width+"px");
                                $('.back').css("width", width+"px");
                                $('.drop').css("height", height+"px");
                                $('.back').css("height", height+"px");
                                $('.drop').css("background-repeat","no-repeat");
                                $('.back').css("background-repeat","no-repeat");
                                $('.drop').css("margin-left", pad+"px");
                                $('.back').css("margin-left", pad+"px");
                            }
                        }
                        
                        //alert(field);
                        
                        $('.drop').css('background-image', 'url()');
                        
                        $('.drop').hide();
                        $('.drop').show();
                        var url = "url(./imagesapp/back.png?"+Math.random()+")";
                        //CH.VC.dropbackground=url;
                        $('.drop').css('background-image', url);
                        $('.back').css('background-image', url);
						
                        //						$(".dd_BG div:last-child").remove();
                        //						$("#leftsidetable td").html("Type your address");
                        
                        //alert(_divId);
                        //   if(_divId=="bannerInner")
                        //          {   
                        makecanvas(_packageType);
                        if(_packageType == 'STANDARD') 
                        {
                            CH.VC2.init();
                            
                            $( ".tools button" ).prop("disabled","disabled");
                            $( ".tools select" ).prop("disabled","disabled");
                            $( ".tools #changebg" ).prop("disabled","");
                            $("#sidebuttons").append("<button name='addtext' class='toolbarViewBtn'  id='frontdivimg'><img src='imagesapp/front_view.png' width='18' alt='Front View' /></button><button name='addtext' class='toolbarViewBtn'  id='backdivimg'><img src='imagesapp/back_view.png' width='18' alt='Back View' /></button>");
                            CH.VC2.to_back();
                            CH.VC2.to_front();
                            $( "#epsbutton" ).prop("disabled","");       
                            //$( ".tools #toolbarViewAction #epsbutton" ).prop("disabled","");       
                        }
                        else if(_packageType == 'BASIC')
                        {
                                
                            
                            CH.VC3.init();
                            $( ".tools button" ).prop("disabled","disabled");
                            $( ".tools select" ).prop("disabled","disabled");
                            $( ".tools #addButton" ).prop("disabled","");
                            $( ".tools #upphot" ).prop("disabled","");
                            $("#sidebuttons").append("<button name='addtext' class='toolbarViewBtn'  id='frontdivimg'><img src='imagesapp/front_view.png' width='18' alt='Front View' /></button><button name='addtext' class='toolbarViewBtn'  id='backdivimg'><img src='imagesapp/back_view.png' width='18' alt='Back View' /></button>");
                            CH.VC3.to_back();
                            CH.VC3.to_front();
                            $( "#epsbutton" ).prop("disabled","");        
                        
                        }
                        else if(_packageType == 'BUSINESS') 
                        {
                            CH.VC.init();
                            
                            				
                            $('#clrpikr').hide();    
                        }
                        putAddressIndd();        				  
                    //}    
                    } 

                })
            });
        }
    });
}


function putAddressIndd()
{
    $('.dd_BG_top').html("<div style='padding-top:10px'>Enter text for back side</div>");
    $('.dd_BG').html("<div id='addressDivindd_bg' style='text-align:left;padding-left:15px;'><div>Address Line 1</div><div id='dd_bgaddress1' style='margin-bottom:4px'><input id='dd_bgaddress1input' type='text' name='addrline1' size='35' /></div><div>Address Line 2</div><div  id='dd_bgaddress2' style='margin-bottom:4px'><input id='dd_bgaddress2input' type='text' name='addrline2' size='35' /></div><div>Telephone</div><div  id='dd_bgtelephone' style='margin-bottom:4px'><input id='dd_bgtelephoneinput' type='text' name='telephone' size='25' /></div><div>Website</div><div  id='dd_bgwebsite' style='margin-bottom:4px'><input id='dd_bgwebsiteinput' type='text' name='website' size='35' /></div></div>");
    matchaddressfromdd_bg();
}


//alert(div);
function changeaddress(){
    $("#leftsidetable td").html("");
    $(".dd_BG div:last-child").remove();
	
}



function getsides()
{

    $.ajax({
                        
        type: "POST",
        url:"getsidebuttons.php",
        data:{
        //temp:bga
        },
        //success:function(data){
        success:function(data){
            //$('#formats').append(data);
            //$('#formats').append("<div style='clear:both'></div>");
            //alert(data);
            $("#sidebuttons").html(data);            
                    
            CH.VC.to_back();
            CH.VC.to_front();
            CH.VC.to_left();
            CH.VC.to_right();
                    
        } 

    });
        

}



function makecanvas()
{
    var oThis=this;
	
    
    
    $('.maindiv').show();

    if(oThis.selected==0)
    {
        $('#leftdivimg').hide();
        $('#rightdivimg').hide();
    }
    else
    {
        $('#leftdivimg').show();
        $('#rightdivimg').show();
    //CH.VC.putchooseformat();
    }

    $('#topMenuChooseDesign').click(function() {
        //putBackGroundIndd();
        if(_packageType == 'STANDARD') loadDesigns(CH.VC2.packagename, true);
        else if(_packageType == 'BASIC') loadDesigns(CH.VC3.packagename, true); 
        else if(_packageType == 'BUSINESS') loadDesigns(CH.VC.packagename, true);						
		
								   
    });
    $('#topMenuChooseAddress').click(function() {
        //putBackGroundIndd();
        if(_showInLeftMenu)
        {
            $('.dd_BG').html("");
            oThis.putAddressIndd();
                
        }					
		
								   
    });
    

}

function notready(){
    alert("not ready");
}
             
function rotateOnMouse (obj, event, pw)
{
    var offset = pw.offset();
    var center_x = (offset.left) + ( $(pw).width() / 2 );
    var center_y = (offset.top) + ( $(pw).height() / 2 );
    var mouse_x = event.pageX;
    var mouse_y = event.pageY;
    var radians = Math.atan2(mouse_x - center_x, mouse_y - center_y);
    var degree = (radians * (180 / Math.PI) * -1) + 100;
    //            window.console.log("de="+degree+","+radians);
    
    //alert(degree);
    $(pw).css('-moz-transform', 'rotate('+degree+'deg)');
    $(pw).css('-webkit-transform', 'rotate('+degree+'deg)');
    $(pw).css('-o-transform', 'rotate('+degree+'deg)');
    $(pw).css('-ms-transform', 'rotate('+degree+'deg)');
		
    obj.lastaction="Rotate";
    obj.element=pw.prop("id");
    
    // var test= obj.packagename////////////////
    // window.console.log(test);
    var index=((pw).prop("id")).substr((pw).prop("id").length-1);
    if(index=="0")
    {
            
        index=10;
    }
    
    //window.console.log(index);
    //window.console.log(obj.items[1].innertxt);
    //window.console.log(obj);
    //window.console.log(degree);
    degree=""+degree;
    
    obj.items[index-1].angle=degree;
//obj.item[index]=degree////////////////////////////////////////////////*/
}

function hookRotation(obj, e)
{
    //window.console.log("rotate");
    obj.destroyDragResize();
    $(".drop div .delete-image").hide();
    $(".drop div .drag-image").hide();
    obj.fl_rotate=true;
    e.stopImmediatePropagation();
    e.preventDefault();
    //$(document).unbind( 'mousemove' );
    $(document).mousemove(function(e){
        if(obj.fl_rotate){
            var element=$(obj.sDiv);
            obj.rotateOnMouse(e,element);
            e.stopImmediatePropagation();
            e.preventDefault();
        } 
    });
}
                
var frontmade=0;




function makeback(){
    $(".sider").append("<div id='back' class='back'></div>");
    $(".back").css("background-image","url('./imagesapp/back.png')");
    //CH.VC.fitbackground();
    //call function
    $(".sider .back").html("<div id='addressDivonback' style='width:260px; text-align:left;padding-left:15px;'><div>Address Line 1</div><div id='backaddress1' style='margin-bottom:4px'><input id='backaddress1input' type='text' name='addrline1' size='35' /></div><div>Address Line 2</div><div  id='backaddress2' style='margin-bottom:4px'><input  id='backaddress2input' type='text' name='addrline2' size='35' /></div><div>Telephone</div><div  id='backtelephone' style='margin-bottom:4px'><input  id='backtelephoneinput' type='text' name='telephone' size='25' /></div><div>Website</div><div  id='backwebsite' style='margin-bottom:4px'><input  id='backwebsiteinput' type='text' name='website' size='35' /></div></div>");
    $(".back").hide();
}



function makeleft(){
    $(".sider").append("<div id='left' class='left'></div>");
    $(".left").css("background-color",CH.VC.leftrightbgcol);
    CH.VC.leftsidebgcolor=939466;
    $(".left").hide();
}

function makeright(){
    
    $(".sider").append("<div id='right' class='right'></div>");
    $(".right").css("background-color",CH.VC.leftrightbgcol);
    CH.VC.rightsidebgcolor=939466;
    $(".right").hide();
}



function cmn_to_back(pckg) {
    $('#clrpikr').hide();
    $(".back").css("background-image","url('./imagesapp/back.png?"+Math.random());
    $('#frontdivimg').show();
    $('#backdivimg').show();
    CH.VC.fitbackground();
    if(pckg=="business")
    {
        $('#leftdivimg').show();
        $('#rightdivimg').show();
    }
    $(".left").hide();
    $(".right").hide();
    $(".tridiv").hide();
    
    $(".drop").hide();
    $(".back").show();
    //$( ".tools #changebg" ).prop("disabled","disabled");
    //$( ".tools #predefinebg" ).prop("disabled","disabled");
    $( ".tools button" ).prop("disabled","disabled");
    $( ".tools select" ).prop("disabled","disabled");
    $( ".tools #toolbarViewAction button" ).prop("disabled","");
    $('#viewLbl').html('Back View');
        
}
function cmn_to_front(pckg){
        
    $('#clrpikr').hide();
        
    $(".left").hide();
    $(".right").hide();
    $(".back").hide();
    $(".drop").show();
    $(".tridiv").show();
            
    $('#frontdivimg').show();
    $('#backdivimg').show();
    
    
    if(pckg=="business")
    {
        $('#leftdivimg').show();
        $('#rightdivimg').show();
        $( ".tools button" ).prop("disabled","");
        $( ".tools select" ).prop("disabled","");
        
    }  
    else if(pckg=="basic"){
   
        $( ".tools button" ).prop("disabled","disabled");
        $( ".tools select" ).prop("disabled","disabled");
        $( ".tools #addButton" ).prop("disabled","");
        $( ".tools #upphot" ).prop("disabled","");
        $( ".tools #toolbarViewAction button" ).prop("disabled","");
        
        
    }
    else if(pckg=="standard"){
        //alert("sdgdf");
        $( ".tools button" ).prop("disabled","disabled");
        $( ".tools select" ).prop("disabled","disabled");
        $( ".tools #changebg" ).prop("disabled","");
        $( ".tools #toolbarViewAction button" ).prop("disabled","");
        
    }
    
    
    // this.initfront_to_back();
    $('#viewLbl').html('Front View');
        
}
    
    
function cmn_to_left(){
    
    $('#clrpikr').show();
    $(".drop").hide();
    $(".right").hide();
    $(".back").hide();
    $(".left").show();
    $(".tridiv").hide();
    
    $('#frontdivimg').show();
    $('#backdivimg').show();
    $('#leftdivimg').show();
    $('#rightdivimg').show();
    
    //required
    $("#clrpikr .miniColors-trigger").css("background-color",CH.VC.leftrightbgcol);
    
    $( ".tools button" ).prop("disabled","disabled");
    $( ".tools select" ).prop("disabled","disabled");
    $( ".tools #toolbarViewAction button" ).prop("disabled","");
    $('#viewLbl').html('Left View');
    window.console.log($(".left").css("background-color"));
    //window.console.log($(".right").css("background-color"));
    CH.VC.leftrightbgcol=($(".left").css("background-color"));
    $("#clrpikr .miniColors-trigger").css("background-color",CH.VC.leftrightbgcol);
}
function cmn_to_right(){
    
    $('#clrpikr').show();
    $(".drop").hide();
    $(".right").show();
    $(".back").hide();
    $(".left").hide();
    $(".tridiv").hide();
    
    $('#frontdivimg').show();
    $('#backdivimg').show();
    $('#leftdivimg').show();
    $('#rightdivimg').show();
    
    
    $("#clrpikr .miniColors-trigger").css("background-color",CH.VC.leftrightbgcol);
    $( ".tools button" ).prop("disabled","disabled");
    $( ".tools select" ).prop("disabled","disabled");
    $( ".tools #toolbarViewAction button" ).prop("disabled","");
    $('#viewLbl').html('Right View');
    //window.console.log($(".left").css("background-color"));
    window.console.log($(".right").css("background-color"));
    CH.VC.leftrightbgcol=($(".left").css("background-color"));
    $("#clrpikr .miniColors-trigger").css("background-color",CH.VC.leftrightbgcol);
} 
    
function matchaddressfromback(){

    // $("#backaddress1 input").change(function(){
    $("#backaddress1 input").live('keyup',function(){
        //alert("sdf");
        document.getElementById("dd_bgaddress1input").value=(this.value);

    });
 
    $("#backaddress2 input").live('keyup',function(){

        //alert("sdf");
        document.getElementById("dd_bgaddress2input").value=(this.value);

    });
    $("#backtelephone input").live('keyup',function(){

        //alert("sdf");
        document.getElementById("dd_bgtelephoneinput").value=(this.value);

    });
    $("#backwebsite input").live('keyup',function(){

        //alert("sdf");
        document.getElementById("dd_bgwebsiteinput").value=(this.value);

    });
 
 
}

function matchaddressfromdd_bg(){
 
 
    $(".container #dd_bgaddress1input").live('keyup',function(){
        document.getElementById("backaddress1input").value=(this.value);
    });
 
 
    $(".container #dd_bgaddress2input").live('keyup',function(){
        document.getElementById("backaddress2input").value=(this.value);
    });
 
 
    $(".container #dd_bgtelephoneinput").live('keyup',function(){
        document.getElementById("backtelephoneinput").value=(this.value);
    });
 
 
    $(".container #dd_bgwebsiteinput").live('keyup',function(){
        document.getElementById("backwebsiteinput").value=(this.value);
    });
 
}

function traverseback(){
   
    
    $('#addressDivonback :input').each(function (index) {

        var newback= new CH.backitem();
        CH.VC.back.push(newback);
        CH.VC.back[index].id=$(this).prop("id");
        CH.VC.back[index].inputvalue=$(this).val();        
    //here
     
        
        
    //window.console.log("index");
    //window.console.log(index);
    //window.console.log("index");
    // do something
    //window.console.log( index, $(this).val() );to print index with the value
    //  window.console.log($(this).val() );
    });

}
function preview(){
    
    $.ajax({
                        
        type: "POST",
        url:"getimagedimensions.php",
        data:{
        //src:oThis.filename
        } ,
        success:function(data){
            //here                    
            var width = data.split(' ')[0];
            //alert(width);
            var height = data.split(' ')[1];
            //alert(height);
                        
                        
                        
            $("#previeweps").dialog("destroy");
            $("#previeweps").dialog({
                modal: true,
                width:width,
                height:height,
                //autoopen: false,
                open:function(event, ui){
                    //var clone=$("#drop").clone();
                    //$(".prev-content").html(clone);
                    var url = "url(./imagesapp/back.png?"+Math.random()+")";
                    $("#previeweps").html("");
                    $("#previeweps").css('background-image', url);
                    $("#previeweps").css("background-repeat","no-repeat");
                    var savedata=(JSON.stringify(CH.VC.items));
                    var q = JSON.parse(savedata);
                    window.console.log(q);
                    var i;
                    var x;
                    for(i=0;i<q.length;++i)
                    {
                        var x=i+1;
            
                        if(CH.VC.items[i].istxt=="1")
                        {
                            $("#previeweps").append("<div id = 'demo"+x+"' class='demo' align='right'><span id='span"+x+"'>"+CH.VC.items[i].innertxt+"</span></div>"); //current
            
                        }
                        else if(CH.VC.items[i].istxt=="0")
                        {
                        
                            var widimg=150;
                            width=parseInt(width);
                            var neww=($("#drop").css("width"));
                            neww=parseInt(neww);
                            var asp=width/neww;
                            widimg=widimg*asp;

                          
                            $.ajax({
                                
                                async : false,
                                type: "POST",
                                url:"getimagefromuploads.php",
                                data:{
                                src:CH.VC.items[i].innertxt
                                } ,
                                success:function(data){
        
                                    
                                    var src=data;
                                    $("#previeweps").append("<div id = 'demo"+x+"' class='demo' align='right'><span id='span"+x+"'><img class='preview' style='width:"+widimg+"px;'  src='uploads"+src+"' /></span></div>"); //current     
                        
                                }
                            });
                
            
                        }    
                    

                        $("#previeweps #demo"+x).addClass("demo");

                        if (q[i].isBold==1)
                        {
                            $("#previeweps #span"+x).addClass("bold");
                        }
                        if (q[i].isItalic==1)
                        {
                            $("#previeweps #span"+x).addClass("italic");
                        }
                        if (q[i].isUnderlined==1)
                        {
                            $("#previeweps #span"+x).addClass("underline");
                        }
                        if (q[i].isRightAligned==1)
                        {
                            $("#previeweps #demo"+x).addClass("rightalign");
                        }
                        if (q[i].isLeftAligned==1)
                        {
                            $("#previeweps #demo"+x).addClass("leftalign");
                        }
                        if (q[i].isCenterAligned==1)
                        {
                            $("#previeweps #demo"+x).addClass("centeralign");
                        }
                        if (q[i].fontcolor!==0)
                        {
                            $("#previeweps #span"+x).css("color" , q[i].fontcolor);
                        }
                        if (q[i].angle!=0)
                        {
                    
                            $("#previeweps #demo"+x).css('-moz-transform', 'rotate('+q[i].angle+'deg)');
                            $("#previeweps #demo"+x).css('-webkit-transform', 'rotate('+q[i].angle+'deg)');
                            $("#previeweps #demo"+x).css('-o-transform', 'rotate('+q[i].angle+'deg)');
                            $("#previeweps #demo"+x).css('-ms-transform', 'rotate('+q[i].angle+'deg)');
                        }
                    
                    
                    
            
                        //window.console.log(q[i].xposition);
                        //window.console.log(q[i].yposition);
                        if (q[i].fontSize!=="0")
                        {
                        
                        
                        
                            height=parseInt(height);//in px
                            //height=$(height).toUnit("pt"); //pt
                        
                            width=parseInt(width);
                            //width=$(width).toUnit("pt");
                        
                            //alert(height);
                            //alert(width);
                            var newh=($("#drop").css("height"));
                            newh=parseInt(newh);
                            //newh=$(newh).toUnit("pt");
                        
                        
                            var neww=($("#drop").css("width"));
                            neww=parseInt(neww);
                            //neww=$(neww).toUnit("pt");
                        
                            var fntsize=($("#span"+x).css("font-size"));
                        
                        
                            fntsize=parseInt(fntsize);
                            //alert(fntsize);
                            // alert(neww/fntsize);
                            var aspect=neww/fntsize;
                        
                        
                            fntsize=width/aspect;
                            //alert ("here: "+fntsize);
                            //alert(q[i].fontSize);
                        
                            //alert(fntsize);
                        
                            $("#previeweps #span"+x).css("font-size" , fntsize+"px");
                        }
                        if (q[i].xposition!==0||q[i].yposition!==0)
                        {
                            var offset = $("#previeweps").offset();
                            //var mul=52;
                            //q[i].xposition=parseInt(q[i].xposition)+(offset.left);
                            //q[i].yposition=q[i].yposition+offset.top-(i*mul);
                            //q[i].yposition=parseInt(q[i].yposition)+(offset.top);
                            q[i].xposition=parseInt(q[i].xposition);
                            q[i].yposition=parseInt(q[i].yposition);
                        
                            /* var x=parseInt(q[i].xposition)+offset.left;
                        var y=parseInt(q[i].yposition)+offset.top;
                        */
                       
                            //alert(q[i].xposition+"px");
                            //alert(q[i].yposition+"px");
                       
                            //               window.console.log("top: "+$("#previeweps #demo"+x).css("top"));
                            //              window.console.log("left: "+$("#previeweps #demo"+x).css("left"));
                       
                      
                            height=parseInt(height);  //original
                            var newh=($("#drop").css("height"));
                            newh=parseInt(newh);  //new 
                            var aspecto= (height/newh);
                            var ypos=(q[i].yposition*aspecto);//+(q[i].angle*2);
                       
                       
                            width=parseInt(width);  //original
                            var neww=($("#drop").css("width"));
                            neww=parseInt(neww);  //new 
                            aspecto= (width/neww);
                            var xpos=(q[i].xposition*aspecto);
                            //alert(q[i].xposition+"px");
                            //alert(q[i].yposition+"px");
                       
                       
                            $("#previeweps #demo"+x).css({
                                left: xpos+"px",
                                top: ypos+"px"
                            });
                        
                        }    
            
                        // window.console.log($("#demo"+x).css(left));
                        // window.console.log($("#demo"+x).css(top));
                    
                        //window.console.log(q[i]);
            
                        x=i+1;
                    }
                    
                    
                    
                    
                    
                },
                buttons: {
                    Cancel: function() {
                        
                        $( this ).dialog( "close" );
                    },
                    Save: function() {
                        $( this ).dialog( "close" );
                        CH.VC.savestate();  
                                  
                    }
                              
                }
            });

                        
                        
                        
                        
                        
                        
        }
    });

//$('#previeweps').css('background-image', 'imagesapp/back.png');












}
